<template>
  <view class="container">
    <!-- 促销头部 -->
    <view class="promo-header">
      <text class="promo-text">天天低价</text>
    </view>

    <!-- 时间选择标签 -->
    <view class="time-tabs">
      <view 
        class="time-tab" 
        v-for="(timeSlot, index) in timeSlots" 
        :key="index"
        :class="{ active: currentTimeSlot === index }"
        @click="selectTimeSlot(index)"
      >
        <view class="time-text">{{ timeSlot.time }}</view>
        <view class="status-text" :class="{ active: currentTimeSlot === index }">
          {{ timeSlot.status }}
        </view>
      </view>
    </view>

    <!-- 商品列表区域 -->
    <view class="content-area">
      <!-- 空状态 -->
      <view v-if="goodsList.length === 0" class="empty-state">
        <view class="empty-text">暂无商品</view>
      </view>

      <!-- 商品列表 -->
      <view v-else class="goods-list">
        <view 
          class="goods-item" 
          v-for="(item, index) in goodsList" 
          :key="item.id || index"
          @click="goToDetail(item)"
        >
          <image class="goods-image" :src="item.image" mode="aspectFill"></image>
          <view class="goods-info">
            <view class="goods-title">{{ item.title }}</view>
            <view class="goods-price">
              <text class="current-price">¥{{ item.currentPrice.toFixed(2) }}</text>
              <text class="original-price">¥{{ item.originalPrice.toFixed(2) }}</text>
            </view>
            <view class="goods-progress">
              <view class="progress-bar">
                <view class="progress-fill" :style="{ width: item.soldPercent + '%' }"></view>
              </view>
              <text class="progress-text">已抢{{ item.soldCount }}/{{ item.totalCount }}</text>
            </view>
            <view class="buy-btn" :class="{ disabled: item.soldCount >= item.totalCount }" @click.stop="buyNow(item)">
              {{ item.soldCount >= item.totalCount ? '已抢完' : '立即抢购' }}
            </view>
          </view>
        </view>
      </view>


    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 时间选择
      currentTimeSlot: 0,
      timeSlots: [
        {
          time: '20:00',
          status: '抢购中',
          isActive: true
        },
        {
          time: '22:00',
          status: '即将开始',
          isActive: false
        },
        {
          time: '23:00',
          status: '即将开始',
          isActive: false
        }
      ],
      

      
      // 商品数据
      goodsList: []
    }
  },
  
  computed: {
    // 当前时间槽
    currentTimeSlotData() {
      return this.timeSlots[this.currentTimeSlot]
    }
  },
  
  onLoad() {
    console.log('秒杀活动页面加载完成')
  },
  
  methods: {

    

    

    
    // 选择时间槽
    selectTimeSlot(index) {
      if (this.currentTimeSlot === index) return
      this.currentTimeSlot = index
    },
    

    
    // 跳转到商品详情
    goToDetail(item) {
      console.log('跳转到商品详情:', item.id)
    },
    
    // 立即抢购
    buyNow(item) {
      console.log('抢购商品:', item.id)
    }
  }
}
</script>

<style scoped>
.container {
  background-color: #f5f5f5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}



/* 促销头部 */
.promo-header {
  background: linear-gradient(135deg, #ff6b35, #f7931e);
  padding: 20px 15px;
  text-align: center;
}

.promo-text {
  font-size: 24px;
  font-weight: bold;
  color: #fff;
  position: relative;
}

.promo-text::after {
  content: '↓';
  position: absolute;
  top: -2px;
  right: -15px;
  font-size: 16px;
  color: #ffeb3b;
}

/* 时间选择标签 */
.time-tabs {
  display: flex;
  background-color: #fff;
  border-bottom: 1px solid #eee;
}

.time-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  cursor: pointer;
}

.time-text {
  font-size: 16px;
  font-weight: 500;
  color: #999;
  margin-bottom: 4px;
}

.status-text {
  font-size: 12px;
  color: #999;
  padding: 2px 8px;
  border-radius: 10px;
  background-color: #f5f5f5;
}

.time-tab.active .time-text {
  color: #ff4444;
}

.time-tab.active .status-text {
  color: #fff;
  background-color: #ff4444;
}

/* 内容区域 */
.content-area {
  flex: 1;
  padding: 15px;
  background-color: #f5f5f5;
}



/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
}

.empty-text {
  font-size: 14px;
  color: #999;
}

/* 商品列表 */
.goods-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.goods-item {
  background-color: #fff;
  border-radius: 8px;
  padding: 15px;
  display: flex;
  gap: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.goods-image {
  width: 100px;
  height: 100px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.goods-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.goods-title {
  font-size: 14px;
  color: #333;
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.goods-price {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.current-price {
  font-size: 18px;
  color: #ff4444;
  font-weight: bold;
}

.original-price {
  font-size: 12px;
  color: #999;
  text-decoration: line-through;
}

.goods-progress {
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background-color: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b35, #f7931e);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 12px;
  color: #666;
}

.buy-btn {
  height: 32px;
  background: linear-gradient(135deg, #ff6b35, #f7931e);
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.buy-btn.disabled {
  background-color: #ccc;
  cursor: not-allowed;
}


</style>
